/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using System.Collections.ObjectModel;

namespace DaveSexton.DocProject.Sandcastle.TopicManagement
{
	public sealed class TypeConfigNode : ApiFilterConfigNode
	{
		#region Public Properties
		public ICollection<MemberConfigNode> Members
		{
			get
			{
				return new ReadOnlyCollection<MemberConfigNode>(members);
			}
		}

		public NamespaceConfigNode Namespace
		{
			get
			{
				return @namespace;
			}
		}

		public MemberConfigNode this[string member]
		{
			get
			{
				return members[member];
			}
		}
		#endregion

		#region Private / Protected
		private readonly ApiFilterConfigNodeCollection<MemberConfigNode> members = new ApiFilterConfigNodeCollection<MemberConfigNode>();
		private readonly NamespaceConfigNode @namespace;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="TypeConfigNode" /> class.
		/// </summary>
		private TypeConfigNode(NamespaceConfigNode @namespace, string name, bool expose)
			: base("type", @namespace, TopicType.Type, name, expose)
		{
			if (@namespace == null)
        throw new ArgumentNullException("namespace");

			this.@namespace = @namespace;
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="TypeConfigNode" /> class for the specified <paramref name="node" />.
		/// </summary>
		internal TypeConfigNode(NamespaceConfigNode @namespace, XPathNavigator node)
			: base(node, TopicType.Type)
		{
			if (@namespace == null)
				throw new ArgumentNullException("namespace");

			this.@namespace = @namespace;
		}
		#endregion

		#region Methods
		public static TypeConfigNode AppendTo(NamespaceConfigNode @namespace, string name, bool expose)
		{
			TypeConfigNode node = new TypeConfigNode(@namespace, name, expose);

			@namespace.AddType(node);

			return node;
		}

		internal void AddMember(MemberConfigNode member)
		{
			members.Add(member);
		}
		#endregion
	}
}
